const EventEmitter = require('events').EventEmitter;
const _InitADObserver = require('./wrapper')
const InitADObserver = require('bindings')('AD-Observer');

var ADObserver = new _InitADObserver({
  hostName: 'ldap.ad.shubuzuo.top',
  port: '389',
  serverUrl: 'ldap.ad.shubuzuo.top:389',
  bindDN: 'cn=administrator,cn=users,dc=test,dc=shubuzuo,dc=top',
  baseDN: 'cn=Users,dc=test,dc=shubuzuo,dc=top',
  password: '1409458062@qq.com',
  changedAttribs: ['name', 'isDeleted', 'uSNChanged'],
  // changedAttribs: 'name',
  filterStr: 'ObjectClass=*',
});
// var ADObserver = new InitADObserver({
//   hostName: 'localhost',
//   port: '389',
//   serverUrl: 'ldap://localhost:389',
//   bindDN: 'cn=administrator,cn=users,dc=test,dc=authing,dc=com',
//   baseDN: 'CN=steamory,CN=users,DC=test,DC=authing,DC=com',
//   password: 'Authing.cn200500404',
//   changedAttribs: ['name', 'isDeleted', 'uSNChanged'],
//   // changedAttribs: 'name',
//   filterStr: 'ObjectClass=*',
// });
// console.log(ADObserver.stopMonitor());


// ADObserver.open((state) => {
//   console.log(state);
// });

// ADObserver.bind((state) => {
//   console.log(state);
// });



const moniter = new EventEmitter();

moniter.on('change', (data) => {
  // 对应变化为 增加 与 修改
  // 也可能是实体转移
  // 直接同步该 实体
  console.log("also change data",data);
});

// moniter.on('add', data => {
//   console.log("add data +++++++++++", data);
// });

moniter.on('del', data => {
  // 对应变化为删除
  console.log("del data: -------------------", data);
});



ADObserver.initMonitor(moniter);

ADObserver.startMonitor(moniter.emit.bind());

// console.log('aaa');
